// 生成随机颜色
export function getRandomHexColor() {
	const hexChars = '0123456789ABCDEF';
	let color = '#';
	for (let i = 0; i < 6; i++) {
		color += hexChars[Math.floor(Math.random() * 16)];
	}
	return color;
}

// 生成一个200项的数组随机颜色
export function getColorsList() {
	const colors = [];
	for (let i = 0; i < 200; i++) {
		colors.push(getRandomHexColor());
	}
	console.log("colors============", colors)
	uni.setStorage({
		key: 'colorsList',
		data: colors,
	})

}




export const getDictData = (dictNum) => {
	let dictList = []
	uni.getStorage({
		key: 'dicts',
		success(e) {
			dictList = e.data
		},

	});

	dictList = dictList[dictNum]

	let targetArr = []
	dictList?.forEach((item, index) => {
		targetArr.push({
			value: item.itemValue,
			text: item.itemText
		})
	})
	console.log("dictList-----------", dictList);
	return targetArr

}

export const formatterDictData = (dictType, target, type) => {
	let data = getDictData(dictType)
	console.log("target------", target)
	if (type == 'arr') {
		let newArr = ''
		if (target.indexOf(',') == 1) {
			newArr = target.split(',')
		} else {
			newArr = target.split()
		}

		let newData = []
		data.forEach((item, index) => {
			if (item.value == newArr[index]) {
				newData.push({

					text: item.text

				})
			}
		})
		return newData;
	} else {
		let result = ''
		data.forEach((item, index) => {
			if (item.value == target) {
				result = item.text
			}
		})
		console.log("result==============", result);
		return result
	}




}